-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EuiColorStops: Feature Stepped ColorStops #4613
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
This is all done to merge please review this @flash1293 @cchaos. |
Pulling Latest Code
Hey @git-anurag-hub, Thanks for getting this started! We'll need to make some changes before this is ready to merge. A couple comments to start: All changes should be scoped to color_stops files. That is, range_highlight should have no knowledge that a "stepped" option exists. At most, the Also, we'll need to account for custom min-max domains. That is, we cannot assume that the scale will always be from 0-1 or 0-100. Just important to keep in mind for calculations. |
Okay will commit changes once I am done with these. 👍 |
@thompsongl It will not be possible to remove the stepped from the range_highlight as making the styles for the fixed or gradient & stepped it totally different but I can do one thing to remove it i.e. I can instead of passing the colors as the prop I can send the background styles directly from the parent component. |
It is possible to create a stepped linear gradient in the same manner as the other gradient types; see an example here: https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient()#gradient_with_multi-position_color_stops
The reason that color_stops logic should not be part of range_highlight is that it is already being used in other components, namely EuiRange and EuiDualRange. We want to avoid further changes to this component, especially when its current props are sufficient for the new use case (i.e., |
Made changes @thompsongl @flash1293. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @flash1293 @thompsongl where is the default grey colour stored maybe in some variable name of something. I am not able to find it. |
Yes, I agree this is how it should work.
Use |
If we provide the color as |
@git-anurag-hub Don't pass |
We can't do that because we have to make the stepped background first before providing it to the css. @thompsongl One thing I can do is provide the hex value of the grey color you are using but I don't think it is the great idea/solution. |
@git-anurag-hub Then you have to refactor your code - the helper function in util shouldn't care about the |
We can't do this because we are using chromajs to make the steps and we need to provide the first color (i.e. grey). @flash1293 @thompsongl |
@git-anurag-hub This is how it should work:
It might be just because you didn't push your current state, but you resolved some comments without changing anything. |
@flash1293 is exactly right. You can think of the gray color before the first stop as an 'empty' space; it has not been configured with a color by the user. For that reason, Let me know if this makes sense, and thanks for sticking with us as we provide feedback; your help is much appreciated |
Np @flash1293 @thompsongl Can please review pr once again as I made the changes asked for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with the picker and the colors behave a little weird:
Two stops, three steps - it looks like I would expect. The first segment takes the first color, the last one takes the last color, the one in the middle takes an interpolated color
But if I drag the first stop to the right, the middle segment turns into the first color until there are only two segments visible:
Do you know why that happens? The segments do get smaller while I'm dragging, so it doesn't make sense for the middle segment to change color.
@@ -45,6 +49,8 @@ import { EuiScreenReaderOnly } from '../../accessibility'; | |||
import { EuiRangeHighlight } from '../../form/range/range_highlight'; | |||
import { EuiRangeTrack } from '../../form/range/range_track'; | |||
import { EuiRangeWrapper } from '../../form/range/range_wrapper'; | |||
// import { colorPalette } from '../../../services/color/color_palette'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused imports, please remove
colors: ColorStop[], | ||
steps: number | ||
) { | ||
const finalStops = [0, ...colors.map((item) => item.stop / 100), 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@git-anurag-hub This logic always assumes a min
of 0 and a max
of 100, but that's not the case - the user can configure min and max. This logic needs to be aware. As far as I can tell that's also the reason for the behavior described here: #4613 (review)
The color segments should be done between the first and last stop
Thanks, @flash1293 This is looking good so far! A couple things I noticed while clicking around the demo: It's possible to get into odd configurations where a colors appears before the drag handle of the previous color (e.g., pink before the yellow handle). Low step counts have the potential to misrepresent the color distribution. Also, should we add a rule to force the step count to be at least equal to the number of drag handles (i.e., minimum of 3 in the above screenshot)? Given your explanation that the stepped gradient is "actually just a quantization postprocessing of the smoothly interpolated palette", both of these seem to be acceptable/expected, but what to get your thoughts. Regarding the
As a consumer, do you need access to the values and start/stop locations of each gradient step? |
Thanks for the check @thompsongl
Yes, this is due to the way the palette is quantized - it's not taking the center of each segments for the color. The first segment is colored by the very first step, the last segment by the very last step, and the places to use color from in between are evenly distributed. This only matches with the center of the segment for the middle segment. This shows from where on the spectrum the individual segments get their color: I thought back and forth on this - another thing we could do is this: But it has other weird edge cases - now there won't be a segment colored exactly like the beginning and end colors, but always a blend - in the example above the first segment would be a blend of green and yellow, the second segment would be a green/yellow blend with less green, and the last one would be perfect yellow with no red at all - which is also weird IMHO. I thought we can start with this and if people complain we can introduce more options - as you mentioned this is an edge case anyway.
Good point, I think we can enforce this on the consumers side, but I would keep the component itself unbiased.
No, that's fine as they will be evenly distributed. As we will have some logic for this on the consumer side anyway, I think the current abstraction level is fine. |
This makes sense to me. The core API is settled, especially if we don't enforce restrictions on step count. Any future changes would likely be visual in nature or add new options. I'll take another review of the code. jenkins test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4613/ |
Snapshot test failure:
|
Jenkins, test this |
@thompsongl Fixed the failing test. As I rely on the |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4613/ |
Jenkins, test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4613/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @git-anurag-hub,
Tested in Chrome, Safari, Edge and Firefox, and LGTM! 🎉
I did a review more focused on the design aspects of the PR, and I moved the steps into a popover to match other examples.
I also added a few prop descriptions.
* Specify the type of stops: | ||
* `fixed`: individual color blocks. | ||
* `gradient`: each color fades into the next. | ||
* `stepped`: interpolation between colors with a fixed number of steps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an explanation for each stopType
. Not sure if this is the best explanation for what the stepped
option does. A better suggestion is welcome. 😄
Co-authored-by: Elizabet Oliveira <[email protected]>
Jenkins, test this |
Thanks @miukimiu ! |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4613/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the one change below
Thanks @git-anurag-hub for getting this started
Thanks @flash1293 for getting it across the finish line
Thanks @miukimiu for the docs improvements
Jenkins, test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4613/ |
Summary
This is to add the new feature to the euiColorStops:- Closes #4570
Checklist